package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.saveChannelDTO;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.listChannelDTO;
import com.heima.wemedia.service.WmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author itlxc
 * @since 2024-07-26
 */
@RestController
@RequestMapping("/api/v1/channel")
@RequiredArgsConstructor
@Slf4j
public class WmchannelController {

    private final WmChannelService wmChannelService;

    @GetMapping("/channels")
    @ApiOperation("查询所有频道")
    public ResponseResult findAll(){
        log.info("查询所有频道");
        return ResponseResult.okResult(wmChannelService.list());
    }

    /**
     * 保存频道
     * @param saveChannelDTO
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody saveChannelDTO saveChannelDTO) {
        log.info("保存频道：{}", saveChannelDTO);
        return wmChannelService.saveChannel(saveChannelDTO);
    }

    /**
     * 频道列表
     * @param listChannelDTO
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody listChannelDTO listChannelDTO) {
        log.info("查询频道列表：{}", listChannelDTO);
        return wmChannelService.listChannels(listChannelDTO);
    }
    @PostMapping("/update")
    public ResponseResult update(@RequestBody saveChannelDTO saveChannelDTO) {
        log.info("更新频道：{}", saveChannelDTO);
        return wmChannelService.updateChannel(saveChannelDTO);
    }

    @GetMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") Long id) {
        log.info("删除频道：{}", id);
        return wmChannelService.delChannel(id);
    }
}
